package week2;

import week2.ArrayStack;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
public class stack {
    public static void main(String[] args) {
        String sentence;
        int b = 0;
        int d = 0;
        int f = 0;
        String result ="";


         Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个句子");
        sentence = scan.nextLine();
        StringTokenizer Tokenizer = new StringTokenizer(sentence);
        int number = Tokenizer.countTokens();
        String[] c = new String[number];
        while (Tokenizer.hasMoreTokens()) {
            ArrayStack stack = new ArrayStack();
            String result1 = "";
            String str = Tokenizer.nextToken();
            for (int a = 0; a < str.length(); a++) {
                stack.push(str.charAt(a));
            }
            while (!stack.isEmpty()) {
                result1 += stack.pop();
            }
            c[b] = result1;
            b++;
        }

        for (int a = 0; a < number; a++){
            result += c[a] + " ";}
        System.out.println(result);
    }
}

//        String sentence="",result="";
//        Scanner scan = new Scanner(System.in);
//        System.out.println("Please enter a sentence.");
//        sentence=scan.nextLine();//让用户输入一个句子
//
//        StringTokenizer stringTokenizer = new StringTokenizer(sentence);//创建一个StringTokenizer对象，把句子中的元素分开来
//        int i = stringTokenizer.countTokens(),a=0;
//        String[] list = new String[i];//创建一个数组以存放倒序后的元素
//
//        do{
//            String str = stringTokenizer.nextToken(),result1="";
//            ArrayStack stack = new ArrayStack();
//            for (int b = 0 ; b< str.length();b++){
//                stack.push(str.charAt(b));//使用栈倒序元素的字符
//            }
//
//            while (!stack.isEmpty()){
//                result1+=stack.pop();//遍历倒序后的字符
//            }
//            list[a]=result1;
//            a++;
//        }
//        while(stringTokenizer.hasMoreTokens()||a<i);
//
//        for (int c = 0 ; c<i;c++){
//            result+=list[c]+" ";//遍历存放元素的数组
//        }
//
//        System.out.println(result);
//    }
//}




